import React from 'react';
import * as datetime from '@/utils/datetime';
import regs from '@/utils/regs';
import Workflow from '@/components/page/Workflow';
import { useModel } from 'umi';
const columns: API.Column[] = [
  {
    title: '申请时间',
    key: 'sqsj',
    dataIndex: 'sqsj',
    dataType: 'date',
    render: (sqsj: any) => datetime.format(sqsj, 'yyyy-MM-dd'),
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
  {
    title: '员工号',
    key: 'sysuserid',
    dataIndex: 'sysuserid',
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
  {
    title: '员工名称',
    key: 'sysusername',
    dataIndex: 'sysusername',
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
  {
    title: '所属部门',
    key: 'organname',
    dataIndex: 'organname',
    dataType: 'string',
    width: 120,
    sorter: true,
    dispaly: true,
  },
  {
    title: '邮箱',
    key: 'email',
    dataIndex: 'email',
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
];
const controls: API.Control[] = [
  {
    name: 'sysuserid',
    label: '员工号',
    rules: [
      { required: true, message: '员工编号不能为空' },
      { min: 6, max: 10, message: '长度不能小于6,大于10' },
      { pattern: regs.alphanum, message: '必须是字母或者数字' },
    ],
    type: 'text',
    dataType: 'string',
    grid: 12 / 24,
  },
  {
    name: 'sysusername',
    label: '员工名称',
    rules: [
      { required: true, message: '员工名称不能为空' },
      { min: 2, max: 10, message: '长度不能小于2,大于30' },
    ],
    type: 'text',
    dataType: 'string',
    grid: 12 / 24,
  },
  {
    name: 'organid',
    label: '所属部门',
    type: 'select',
    grid: 12 / 24,
    fetch: {
      tableName: 'Organization',
      optionTpl: 'Name',
      valueTpl: 'ID',
      parentTpl: 'OrganID',
      isDao: true,
    },
    dataType: 'number',
    placeholder: '请选择所属部门...',
    rules: [{ required: true, message: '所属部门不能为空' }],
  },
  {
    name: 'email',
    label: '邮箱',
    type: 'text',
    grid: 12 / 24,
    rules: [
      { required: true, message: '邮箱不能为空' },
      { pattern: regs.email, message: '邮箱格式不正确' },
    ],
  },
];

const SpYhsq: React.FC = () => {
  const { user } = useModel('@@initialState', (ret) => ({
    user: ret.initialState?.user,
  }));
  return (
    <Workflow
      taskDaoName="SpYhsq"
      taskColumns={columns}
      taskControls={controls}
      editExtraVals={{ sqr: user!.userID }}
      initSorter={{ FieldName: 'SQSJ', Direction: 'ASC' }}
      title="新员工申请"
      titleColNames={['sysuserid', 'sysusername']}
      keyColName="frid"
      canAdd={true}
      canUpdate={true}
      canDelete={true}
    />
  );
};

export default SpYhsq;
